package com.villaday.idf.service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import android.content.Context;
import android.content.Intent;
import android.os.Message;
import android.util.Log;

import com.villaday.idf.MainActivity;
import com.villaday.idf.activity.BourbonListActivity;
import com.villaday.idf.activity.CashWithdrawalActivity;
import com.villaday.idf.activity.H5Activity;
import com.villaday.idf.activity.HouseDetailsActivityFor3;
import com.villaday.idf.activity.InviteFriendActivity;
import com.villaday.idf.activity.MessageListType0Activity;
import com.villaday.idf.activity.MyOrderDetailActivity;
import com.villaday.idf.activity.SearchBournActivity;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.model.GeTuiMessageEntity;

import static com.villaday.idf.util.Constant.URL.upgrade;

/**
 * 继承 GTIntentService 接收来自个推的消息, 所有消息在线程中回调, 如果注册了该服务, 则务必要在 AndroidManifest中声明, 否则无法接受消息<br>
 * onReceiveMessageData 处理透传消息<br>
 * onReceiveClientId 接收 cid <br>
 * onReceiveOnlineState cid 离线上线通知 <br>
 * onReceiveCommandResult 各种事件处理回执 <br>
 */
public class GeTuiIntentService {

} /*extends GTIntentService {
    private Gson gson = new GsonBuilder().create();
    private String title;

    public GeTuiIntentService() {

    }

    @Override
    public void onReceiveServicePid(Context context, int pid) {
    }

    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage msg) {
        String s = new String(msg.getPayload());
        Log.e("s11", s);

        GeTuiMessageEntity geTuiMessageEntity = gson.fromJson(s, GeTuiMessageEntity.class);

        int type = geTuiMessageEntity.getType();

        // "type": integer, 0无跳转，1跳转APP页面，2链接跳转内嵌webView,3 版本更新
        if (type == 1) {
            //跳转APP页面
                *//*
                *   "idfAppPage": string, 定义的页面路径,
                    "params": {
                     id: "xxxxxx", app页面对应的参数，后期根据需要补充
                               },
                * *//*

            if ("page/home".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/home";  首页

                Intent intent = new Intent(this, MainActivity.class);
                intent.putExtra("type", "page/home");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);


            } else if ("page/home/material".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/home/material";  首页-动态(material)
                Intent intent = new Intent(this, MainActivity.class);

                intent.putExtra("type", "page/home/material");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/home/presell".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/home/presell";  首页-特卖(presell)
                Intent intent = new Intent(this, MainActivity.class);
                intent.putExtra("type", "page/home/presell");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/home/topic".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/home/topic";  首页-发现(topic)
                Intent intent = new Intent(this, MainActivity.class);
                intent.putExtra("type", "page/home/topic");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/village".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/village";  目的地列表页
                Intent intent = new Intent(this, MainActivity.class);

                intent.putExtra("type", "page/village");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);


            } else if ("page/village/detail".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/village/detail";  目的地详情页
                Intent intent = new Intent(this, BourbonListActivity.class);

                intent.putExtra("villageId", geTuiMessageEntity.getParams().getId());
                intent.putExtra("city", "");
                intent.putExtra("area", "");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            } else if ("page/search".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/search";  房源搜索索引页

                Intent intent = new Intent(this, SearchBournActivity.class);
                intent.putExtra("cityId", geTuiMessageEntity.getParams().getId());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            } else if ("page/search/result".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/search/result";  房源搜索结果页
                Intent intent = new Intent(this, BourbonListActivity.class);
                intent.putExtra("villageId", geTuiMessageEntity.getParams().getId());
                intent.putExtra("city", "");
                intent.putExtra("area", "");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            } else if ("page/house/detail".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/house/detail";  房源详情页
                //普通房源
                Intent intent = new Intent(this, HouseDetailsActivityFor3.class);
                intent.putExtra("houseId", geTuiMessageEntity.getParams().getId());
                intent.putExtra("persellId", "");
//                    intent.putExtra("type", data.get(position).getType());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/presell/detail".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/presell/detail";  房源详情页
                //特卖房源
                Intent intent = new Intent(this, HouseDetailsActivityFor3.class);
                intent.putExtra("houseId", geTuiMessageEntity.getParams().getId());
                intent.putExtra("persellId", geTuiMessageEntity.getParams().getId());
                intent.putExtra("presellProduct", true);
//                    intent.putExtra("type", data.get(position).getType());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/vip".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/vip";  VIP
                Intent intent = new Intent(this, MainActivity.class);
                intent.putExtra("type", "page/vip");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/vip/share".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/vip/share";  vip邀请好友分享页
                Intent intent = new Intent(this, InviteFriendActivity.class);

                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/vip/draw".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/vip/draw";  vip提款页
                Intent intent = new Intent(this, CashWithdrawalActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/member".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/member";  我的
                Intent intent = new Intent(this, MainActivity.class);
                intent.putExtra("type", "page/member");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            } else if ("page/member/order".equals(geTuiMessageEntity.getIdfAppPage())) {
                //"page/member/order";  我的订单

                Intent intent = new Intent(this, MyOrderDetailActivity.class);
                intent.putExtra("orderNo", geTuiMessageEntity.getParams().getId());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            } else {

                Intent intent1 = new Intent(context, MainActivity.class);
                intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                context.startActivity(intent1);
            }


        } else if (type == 2) {
            //链接跳转内嵌webView

            Intent intent = new Intent(this, H5Activity.class);
            intent.putExtra("title", title + "");
            intent.putExtra("url", geTuiMessageEntity.getLink());
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(intent);

        } else if (type == 3) {
            //版本更新
            Intent intent = new Intent(this, MainActivity.class);
            intent.putExtra("type", "page/home");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(intent);
        } else {

            Intent intent1 = new Intent(context, MainActivity.class);

            intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent1);
        }


    }

    @Override
    public void onReceiveClientId(Context context, String clientid) {
        Log.e(TAG, "onReceiveClientId -> " + "clientid = " + clientid);
        AppContext.getuiPushId = clientid;
    }

    @Override
    public void onReceiveOnlineState(Context context, boolean online) {
    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage cmdMessage) {
        Log.e("tag", cmdMessage.toString());
    }

    @Override
    public void onNotificationMessageArrived(Context context, GTNotificationMessage msg) {
        Log.e("tag", msg.toString());
    }

    @Override
    public void onNotificationMessageClicked(Context context, GTNotificationMessage msg) {
        Log.e("tag", msg.toString());
        title = msg.getTitle();
    }
}
*/